home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2018 January / PCgo 01-2018 CD-ROM Germany.iso / nw.pak / Unnamed File 004916.txt < prev    next >
Encoding:
Text File  |  2015-07-29  |  3.8 KB  |  140 lines

  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. // This module implements the public-facing API functions for the <webview> tag.
  6.  
  7. var WebViewInternal = require('webViewInternal').WebViewInternal;
  8. var WebViewImpl = require('webView').WebViewImpl;
  9.  
  10. // An array of <webview>'s public-facing API methods. Methods without custom
  11. // implementations will be given default implementations. Default
  12. // implementations come from createDefaultApiMethod() in web_view.js.
  13. var WEB_VIEW_API_METHODS = [
  14.   // Navigates to the previous history entry.
  15.   'back',
  16.  
  17.   // Returns whether there is a previous history entry to navigate to.
  18.   'canGoBack',
  19.  
  20.   // Returns whether there is a subsequent history entry to navigate to.
  21.   'canGoForward',
  22.  
  23.   // Clears browsing data for the WebView partition.
  24.   'clearData',
  25.  
  26.   // Injects JavaScript code into the guest page.
  27.   'executeScript',
  28.  
  29.   // Initiates a find-in-page request.
  30.   'find',
  31.  
  32.   // Navigates to the subsequent history entry.
  33.   'forward',
  34.  
  35.   // Returns Chrome's internal process ID for the guest web page's current
  36.   // process.
  37.   'getProcessId',
  38.  
  39.   // Returns the user agent string used by the webview for guest page requests.
  40.   'getUserAgent',
  41.  
  42.   // Gets the current zoom factor.
  43.   'getZoom',
  44.  
  45.   // Navigates to a history entry using a history index relative to the current
  46.   // navigation.
  47.   'go',
  48.  
  49.   // Injects CSS into the guest page.
  50.   'insertCSS',
  51.  
  52.   // Indicates whether or not the webview's user agent string has been
  53.   // overridden.
  54.   'isUserAgentOverridden',
  55.  
  56.   // Prints the contents of the webview.
  57.   'print',
  58.  
  59.   // Reloads the current top-level page.
  60.   'reload',
  61.  
  62.   // Override the user agent string used by the webview for guest page requests.
  63.   'setUserAgentOverride',
  64.  
  65.   // Changes the zoom factor of the page.
  66.   'setZoom',
  67.  
  68.   // Stops loading the current navigation if one is in progress.
  69.   'stop',
  70.  
  71.   // Ends the current find session.
  72.   'stopFinding',
  73.  
  74.   // Forcibly kills the guest web page's renderer process.
  75.   'terminate'
  76. ];
  77.  
  78. // -----------------------------------------------------------------------------
  79. // Custom API method implementations.
  80.  
  81. WebViewImpl.prototype.back = function(callback) {
  82.   return this.go(-1, callback);
  83. };
  84.  
  85. WebViewImpl.prototype.canGoBack = function() {
  86.   return this.entryCount > 1 && this.currentEntryIndex > 0;
  87. };
  88.  
  89. WebViewImpl.prototype.canGoForward = function() {
  90.   return this.currentEntryIndex >= 0 &&
  91.       this.currentEntryIndex < (this.entryCount - 1);
  92. };
  93.  
  94. WebViewImpl.prototype.executeScript = function(var_args) {
  95.   return this.executeCode(WebViewInternal.executeScript,
  96.                           $Array.slice(arguments));
  97. };
  98.  
  99. WebViewImpl.prototype.forward = function(callback) {
  100.   return this.go(1, callback);
  101. };
  102.  
  103. WebViewImpl.prototype.getProcessId = function() {
  104.   return this.processId;
  105. };
  106.  
  107. WebViewImpl.prototype.getUserAgent = function() {
  108.   return this.userAgentOverride || navigator.userAgent;
  109. };
  110.  
  111. WebViewImpl.prototype.insertCSS = function(var_args) {
  112.   return this.executeCode(WebViewInternal.insertCSS, $Array.slice(arguments));
  113. };
  114.  
  115. WebViewImpl.prototype.isUserAgentOverridden = function() {
  116.   return !!this.userAgentOverride &&
  117.       this.userAgentOverride != navigator.userAgent;
  118. };
  119.  
  120. WebViewImpl.prototype.print = function() {
  121.   return this.executeScript({code: 'window.print();'});
  122. };
  123.  
  124. WebViewImpl.prototype.setUserAgentOverride = function(userAgentOverride) {
  125.   this.userAgentOverride = userAgentOverride;
  126.   if (!this.guest.getId()) {
  127.     // If we are not attached yet, then we will pick up the user agent on
  128.     // attachment.
  129.     return false;
  130.   }
  131.   WebViewInternal.overrideUserAgent(this.guest.getId(), userAgentOverride);
  132.   return true;
  133. };
  134.  
  135. // -----------------------------------------------------------------------------
  136.  
  137. WebViewImpl.getApiMethods = function() {
  138.   return WEB_VIEW_API_METHODS;
  139. };
  140.